package com.sangeng.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器配置
 */
public class MyInterceptor2 implements HandlerInterceptor {

    /**
     * 目标方法执行之前
     * @param request  当前请求对象
     * @param response 响应对象
     * @param handler 相当于真正能够处理请求的handler方法封装成对象.
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle2");
        //返回值代表是否放行 true放行,false不放行 后面方法不执行
        return true;
    }

    /**handler方法执行之后执行,可以对域中的数据进行修改,也可以修改跳转页面
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle2");
    }

    /**
     * 最后执行,也没有方法修改数据,一般进行资源释放的操作
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion2");
    }
}
